using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.resource
{
[System.Serializable]
public  class Scene :   cfg.EditorReadWriter 
 {

    public string name  = "";
     public string decs  = "";
     public string path  = "";
     public cfg.map.Vector2 pos  = new cfg.map.Vector2();
     public float xSize ;
     public float zSize ;
     public string miniMap  = "";
     public float miniXsize ;
     public float miniZsize ;
     


    public const int TYPE_ID = 875210410;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(9);
        os.WriteSize(Tag.STRING | (1 << Tag.TAG_SHIFT));  os.WriteString(name);  
         os.WriteSize(Tag.STRING | (2 << Tag.TAG_SHIFT));  os.WriteString(decs);  
         os.WriteSize(Tag.STRING | (3 << Tag.TAG_SHIFT));  os.WriteString(path);  
         os.WriteSize(Tag.BEAN | (4 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_map_Vector2(pos,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.FLOAT | (5 << Tag.TAG_SHIFT));  os.WriteFloat(xSize);  
         os.WriteSize(Tag.FLOAT | (6 << Tag.TAG_SHIFT));  os.WriteFloat(zSize);  
         os.WriteSize(Tag.STRING | (7 << Tag.TAG_SHIFT));  os.WriteString(miniMap);  
         os.WriteSize(Tag.FLOAT | (8 << Tag.TAG_SHIFT));  os.WriteFloat(miniXsize);  
         os.WriteSize(Tag.FLOAT | (9 << Tag.TAG_SHIFT));  os.WriteFloat(miniZsize);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.STRING | (1 << Tag.TAG_SHIFT)):   name = os.ReadString(); break;  
             case (Tag.STRING | (2 << Tag.TAG_SHIFT)):   decs = os.ReadString(); break;  
             case (Tag.STRING | (3 << Tag.TAG_SHIFT)):   path = os.ReadString(); break;  
             case (Tag.BEAN | (4 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); pos = cfg.Extensions.unmarshal_compatible_cfg_map_Vector2(os); os = _oldOs; break; }   
             case (Tag.FLOAT | (5 << Tag.TAG_SHIFT)):   xSize = os.ReadFloat(); break;  
             case (Tag.FLOAT | (6 << Tag.TAG_SHIFT)):   zSize = os.ReadFloat(); break;  
             case (Tag.STRING | (7 << Tag.TAG_SHIFT)):   miniMap = os.ReadString(); break;  
             case (Tag.FLOAT | (8 << Tag.TAG_SHIFT)):   miniXsize = os.ReadFloat(); break;  
             case (Tag.FLOAT | (9 << Tag.TAG_SHIFT)):   miniZsize = os.ReadFloat(); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "Scene");
        ele.WriteStartElement("name"); ele.WriteAttributeString("id", "1"); ele.WriteString2(name); ele.WriteEndElement();
         ele.WriteStartElement("decs"); ele.WriteAttributeString("id", "2"); ele.WriteString2(decs); ele.WriteEndElement();
         ele.WriteStartElement("path"); ele.WriteAttributeString("id", "3"); ele.WriteString2(path); ele.WriteEndElement();
         ele.WriteStartElement("pos"); ele.WriteAttributeString("id", "4"); cfg.Extensions.xml_marshal_cfg_map_Vector2(pos,ele); ele.WriteEndElement();
         ele.WriteStartElement("xSize"); ele.WriteAttributeString("id", "5"); ele.WriteFloat(xSize); ele.WriteEndElement();
         ele.WriteStartElement("zSize"); ele.WriteAttributeString("id", "6"); ele.WriteFloat(zSize); ele.WriteEndElement();
         ele.WriteStartElement("miniMap"); ele.WriteAttributeString("id", "7"); ele.WriteString2(miniMap); ele.WriteEndElement();
         ele.WriteStartElement("miniXsize"); ele.WriteAttributeString("id", "8"); ele.WriteFloat(miniXsize); ele.WriteEndElement();
         ele.WriteStartElement("miniZsize"); ele.WriteAttributeString("id", "9"); ele.WriteFloat(miniZsize); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  name = ele.ReadString2(); break; 
                 case 2:  decs = ele.ReadString2(); break; 
                 case 3:  path = ele.ReadString2(); break; 
                 case 4:  pos = cfg.Extensions.xml_unmarshal_cfg_map_Vector2(ele); break; 
                 case 5:  xSize = ele.ReadFloat(); break; 
                 case 6:  zSize = ele.ReadFloat(); break; 
                 case 7:  miniMap = ele.ReadString2(); break; 
                 case 8:  miniXsize = ele.ReadFloat(); break; 
                 case 9:  miniZsize = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "name":  name = ele.ReadString2(); break; 
                 case "decs":  decs = ele.ReadString2(); break; 
                 case "path":  path = ele.ReadString2(); break; 
                 case "pos":  pos = cfg.Extensions.xml_unmarshal_cfg_map_Vector2(ele); break; 
                 case "x_size":  xSize = ele.ReadFloat(); break; 
                 case "z_size":  zSize = ele.ReadFloat(); break; 
                 case "mini_map":  miniMap = ele.ReadString2(); break; 
                 case "mini_xsize":  miniXsize = ele.ReadFloat(); break; 
                 case "mini_zsize":  miniZsize = ele.ReadFloat(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
